package leetcode.p1;

import java.util.HashMap;
import java.util.Map;

public class Solution {
    public static void main(String[] args) {
       int[] a =  new int[]{2,7,11,15};
        int target = 18;
        for (int i : towSum(a, target)) {
            System.out.println(i);
        }
    }

    public static int [] towSum(int []numbers,int target) {
        int[] res = new int[2];
        Map<Integer,Integer> map = new HashMap<>();
        for (int i=0; i < numbers.length; i++) {
            if(map.containsKey(target - numbers[i])) {
                res[1] = i;
                res[0] = map.get(target-numbers[i]);
            }
            map.put(numbers[i],i);
        }
        return res;
    }


}
